// created by jimmy 2016/2/19
/*监听向下滑动*/
$(document).ready(function() {
    if (!isIELow()) {
        setDufault();
        scrollY();
        $(window).bind('scroll', scrollY);
    } else {
        // $.nmDebug.log();

        var arr = $(".headClick").find(".head-click-text");
        arr.each(function(i) {
            if (i == 0) {
                $(this).addClass("normal-select");
                $(this).removeClass("non-select");
            } else {
                $(this).addClass("normal-hover");
                $(this).removeClass("non-hover");
            }
        });
        // $(".headClick").children(".head-click-text")[0].addClass("normal-select");
        // $(".headClick").children(".head-click-text")[1].addClass("normal-hover");
        // $(".headClick").children(".head-click-text")[2].addClass("normal-hover");
    }

    $(".index-header .search-icon img")[0].src = "../images/icon_search_gray.png"/*tpa=http://www.quyundong.com/gosport/index/images/icon_search_gray.png*/;
    $(".index-banner .search-icon img")[0].src = "../images/icon_search_white.png"/*tpa=http://www.quyundong.com/gosport/index/images/icon_search_white.png*/;
    $(".weixin-btn").hover(function() {
        $(".weixin-code")[0].style.display = "block";
    });

    $(".weixin-btn").mouseleave(function() {
        $(".weixin-code")[0].style.display = "none";
    });

    var loginCallBack1 = function() {
        requestBusinessList(true);
    };

    setLoginCallBack(loginCallBack1);
});

loginCallBack1 = function() {

}


function setDufault() {
    $("#imgLogoWhite").css({ "opacity": 1 });
    $("#imgLogoBlue").css({ "opacity": 0 });

    $("#arrowBlack").css({ "opacity": 1 });
    $("#arrowWhite").css({ "opacity": 0 });

    $("#userArrowBlack").css({ "opacity": 0 });
    $("#userArrowWhite").css({ "opacity": 1 });

    $("#cityClick").css({ "background-color": "rgb(255,255,255)" });
    $("#cityText").css({ "color": "rgb(34,34,34)" });
}

/*计算*/
function scrollY() {

    if ($(window).scrollTop() < 210) {

        $("#headClickText1").removeClass("normal-select");
        $("#headClickText2").removeClass("normal-hover");
        $("#headClickText3").removeClass("normal-hover");

        $("#headClickText1").addClass("non-select");
        $("#headClickText2").addClass("non-hover");
        $("#headClickText3").addClass("non-hover");
    } else {

        $("#headClickText1").removeClass("non-select");
        $("#headClickText2").removeClass("non-hover");
        $("#headClickText3").removeClass("non-hover");

        $("#headClickText1").addClass("normal-select");
        $("#headClickText2").addClass("normal-hover");
        $("#headClickText3").addClass("normal-hover");
    }

    if ($(window).scrollTop() > 160) {
        var opacity = ($(window).scrollTop() - 160) * 0.008333;
        $("#indexSearch").css({ "opacity": opacity });
        $("#indexSearch")[0].style.display = "inline-block";

    } else {
        $("#indexSearch")[0].style.display = "none";
        $("#indexSearch").css({ "opacity": 0 });
    }

    if ($(window).scrollTop() < 510) {
        $("#indexHeader").css({ "border-bottom": "0px" });
    }

    if ($(window).scrollTop() <= 280) {
        setHeaderBg($(window).scrollTop());
        setCityBg($(window).scrollTop());
        setCityTextCol($(window).scrollTop());
        setLogoTextCol($(window).scrollTop());
        setLogo($(window).scrollTop());


    } else {
        $("#indexHeader").css({ "background-color": "rgba(255,255,255,1)" });
        $("#cityClick").css({ "background-color": "rgb(79,109,207)" });
        $("#cityText").css({ "color": "rgb(255,255,255)" });
        $("#headText").css({ "color": "rgb(34,34,34)" });
        $(".head-click-text").css({ "color": "rgb(34,34,34)" });
        $(".head-mime-text").css({ "color": "rgb(34,34,34)" });
        $("#imgLogoWhite").css({ "opacity": 0 });
        $("#arrowBlack").css({ "opacity": 0 });
        $("#imgLogoBlue").css({ "opacity": 1 });
        $("#arrowWhite").css({ "opacity": 1 });
        $("#indexSearch").css({ "opacity": 1 });

        $("#userArrowBlack").css({ "opacity": 1 });
        $("#userArrowWhite").css({ "opacity": 0 });

        if ($(window).scrollTop() >= 510) {
            $("#indexHeader").css({ "border-bottom": "1px solid #e1e1e1" });
        } else {
            $("#indexHeader").css({ "border-bottom": "0px" });
        }
    }
}

function setHeaderBg(y) {
    var r = parseInt(203 + y * 0.18571);
    var g = parseInt(206 + y * 0.175);
    var b = parseInt(210 + y * 0.16071);
    var a = 0.3 + y * 0.0025;
    if (r > 255)
        r = 255;
    if (g > 255)
        g = 255;
    if (b > 255)
        b = 255;
    if (a > 1)
        a = 1;
    $("#indexHeader").css({ "background-color": "rgba(" + r + "," + g + "," + b + "," + a + ")" });
}

function setCityBg(y) {
    var r = parseInt(255 - y * 0.62857);
    var g = parseInt(255 - y * 0.52142);
    var b = parseInt(255 - y * 0.17142);

    $("#cityClick").css({ "background-color": "rgb(" + r + "," + g + "," + b + ")" });
}

function setCityTextCol(y) {
    var r = parseInt(0 + y * 0.91071);
    var g = parseInt(0 + y * 0.91071);
    var b = parseInt(0 + y * 0.91071);

    $("#cityText").css({ "color": "rgb(" + r + "," + g + "," + b + ")" });
}

function setLogoTextCol(y) {
    var r = parseInt(255 - y * 0.789285);
    var g = parseInt(255 - y * 0.789285);
    var b = parseInt(255 - y * 0.789285);

    $("#headText").css({ "color": "rgb(" + r + "," + g + "," + b + ")" });
    $(".head-click-text").css({ "color": "rgb(" + r + "," + g + "," + b + ")" });
    $(".head-mime-text").css({ "color": "rgb(" + r + "," + g + "," + b + ")" });
}

function setLogo(y) {
    var opacitySub = 1 - y * 0.003571;
    var opacityAdd = y * 0.003571;
    $("#imgLogoWhite").css({ "opacity": opacitySub });
    $("#imgLogoBlue").css({ "opacity": opacityAdd });

    $("#arrowBlack").css({ "opacity": opacitySub });
    $("#arrowWhite").css({ "opacity": opacityAdd });

    $("#userArrowBlack").css({ "opacity": opacityAdd });
    $("#userArrowWhite").css({ "opacity": opacitySub });
}
